package com.feature.core.rabbitmq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.support.ListenerExecutionFailedException;
import org.springframework.util.ErrorHandler;

public class LogConsumeErrorHandle implements ErrorHandler {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void handleError(Throwable t) {
        ListenerExecutionFailedException exception = (ListenerExecutionFailedException) t;
        Message message = exception.getFailedMessage();
        MessageProperties messageProperties = message.getMessageProperties();
        String body = message.toString();
        String traceID = String.valueOf(messageProperties.getHeaders().get("traceID"));
        this.logger.error("消息接收失败状态提示,TRACEID:{},MSGID:{},消息体:[{}],详情请查看数据收集平台,异常信息:{}", new Object[] { traceID, messageProperties.getMessageId(), body, t.toString() });
        logger.error("", t);
    }
}
